Skip to content

A mesh that does not deform is held compacted - #305

Merged
wryyx merged 1 commit into
meshy-dev:mainfrom
wryyx:blas-compaction
Dec 2, 2026
Merged

wryyx merged 1 commit into
meshy-dev:mainfrom
wryyx:blas-compaction

Conversation

@wryyx

@wryyx wryyx commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

A BLAS is built into the worst case its geometry could need, and a build that is done can say what it does need. The scene's upload built every BLAS and kept it as built: Bistro's 2.8 million triangles held 293 MB of them, Tokyo's 23 million 2.4 GB.

What changes

  • Gpu::upload. A mesh that does not deform is built once. Its BLAS (traced fast, as before) is copied when its batch's build is done into a structure of the size the build reported, and the one it was built in is freed. The batches are as they were, and a batch is compacted before the next is built: what is held at once is the compacted ones and one batch as built. Deforming meshes (posed skinned models', particle systems') are rebuilt every pose and stay as built; so do the meshes edits make and the procedural boxes'.
  • The TLAS was built with the last batch. A compacted copy is a write of the queue's own and goes out with whatever is submitted next. Where several views share a device (the unit suite's tests, side by side) it went out with another's submit, the TLAS was then built over a structure whose copy was not done, and on Metal a TLAS built so loses the instance: five tests failed in one run of the suite, none of them alone. The copies are now submitted and waited for and the TLAS built after them, by itself. With that the suite passed five times running; with the wait taken out again it failed in two runs of two.
  • Edits. wgpu builds no compacted structure again (a validation error). A mesh of the build whose geometry an edit rewrites where it lies takes a new BLAS of the same geometries first, built fast as an edit's, and is built again in that one from then on (Gpu::renew_mesh).
  • THREERT_BLAS_COMPACT=0 leaves every BLAS as built.

Measured (Apple M4, Metal)

scene BLASes as built compacted
Tokyo (23 M triangles, 1,248 structures) 2,401 MB 1,129 MB
Bistro (2.8 M, one structure) 293.1 MB 137.1 MB
Zero-Day (5.9 M, nearly all in one mesh) 608.2 MB 488.7 MB
a small scene 6.4 MB 2.8 MB
a plaza of skinned mannequins 5.6 MB 5.6 MB (none to compact)
  • Bistro's offline render with and without is the same in every pixel.
  • Five clips alternated (without, with, with, without), a frame's GPU time: the largest 17.80 → 17.72 ms, the others within 1 % and none slower by more than 0.1 %.
  • Twelve clips against offline, this build beside main's (main, this, this, main): ΔE the same on every clip to 0.01, the frame within 0.5 % on eleven (on the twelfth main's first run was the slow one), loading within its own spread.

Limits

  • tri_blas_mb is what the builds allocate, as it was: wgpu does not hand out a structure's size. (The sizes above are wgpu-core's own, printed for this measurement.) A function for it in the vendored wgpu was written and taken out again: the browser's module is built against the released wgpu, and the renderer's source is kept to what that one has.
  • A mesh that comes by an edit (a streamed city's cells are those) is held as built.
  • Not checked on Vulkan.

Checks

Unit suite 297 (one new: a compacted mesh's geometry changed where it lies, twice, each against a build; without the new BLAS it fails with wgpu's error), render suite 276, npm run typecheck, npm test, and the two wasm32 builds (renderer as a library, renderer/web).

🤖 Generated with Claude Code

A BLAS is built into the worst case its geometry could need, and a build that
is done can say what it does need. The scene's upload built every BLAS and
kept it as built.

A mesh that does not deform is built once: its BLAS, traced fast as before,
is copied when its batch's build is done into a structure of the size the
build reported, and the one it was built in is freed. The builds go in
batches as before and a batch is compacted before the next is built, so what
is held at once is the compacted ones and one batch as built. Deforming
meshes (posed skinned models', particle systems') are rebuilt every pose and
stay as built, as do the meshes edits make and the procedural boxes'.

- The TLAS was built with the last batch. A compacted copy is a write of the
  queue's own and goes out with whatever is submitted next: where several
  views share a device it went out with another's submit, the TLAS was built
  over a structure whose copy was not done, and on Metal that loses the
  instance (five unit tests failed in a run of the suite, none alone). The
  copies are submitted and waited for, then the TLAS is built by itself.
- wgpu builds no compacted structure again. A mesh of the build whose
  geometry an edit rewrites where it lies takes a new BLAS of the same
  geometries first, built fast as an edit's (`Gpu::renew_mesh`).
- `THREERT_BLAS_COMPACT=0` leaves every BLAS as built.

Measured on an Apple M4 (Metal; the roadmap entry has the figures): Tokyo's
1,248 structures 2,401 MB -> 1,129, Bistro's 293 -> 137, Zero-Day's 608 ->
489, a scene of skinned models alone nothing. Bistro's offline render is the
same in every pixel; twelve clips beside main's build have its pictures and
its frame time (within 0.5 %), and load in the time they took.

`tri_blas_mb` is still what the builds allocate: wgpu does not hand out a
structure's size. Not done: the meshes that come by edits (a streamed city's
cells) stay as built. Not checked on Vulkan.

Unit suite 297 (one new), render suite 276.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@wryyx
wryyx merged commit 07aaa2c into meshy-dev:main Dec 2, 2026
10 checks passed
wryyx added a commit to wryyx/ThreeRT that referenced this pull request Dec 2, 2026
A cutout's maps (renderer/src/cutout.rs) are made of its triangles' texture
coordinates when the scene is prepared, and an instance an edit places takes
those of the scene's instances of its mesh. It took them too when the edit
had rewritten that mesh where it lies (a `dynamicGeometry` mesh, the same
sections): an emitter's shadow rays then asked the map of the triangles the
mesh had had. A card's texture coordinates mirrored at run time kept its old
picture of light and shadow on the ground.

The edit state keeps the meshes whose triangles an edit wrote (a new mesh, a
freed one's slot, one rewritten where it lies), and an instance of one takes
no map: its cutout is opaque to those rays, as a cutout whose material or
texture was edited already is, until the scene is prepared again. To make
the map again at the edit needs the texture's pixels and room in the maps'
stream then: not done.

`shadow/cutout-emitter-geometry-edit-live`: the card of
`shadow/cutout-emitter-side` with its u mirrored after three frames. The
point the old map lit, against a point a lamp under the card lights: 0.25
before (under both traversals), 0.003 now; with the alpha tested 0.085.

Unit suite 297, render suite 277 (on main with meshy-dev#305).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@wryyx
wryyx deleted the blas-compaction branch December 2, 2026 16:28
wryyx added a commit that referenced this pull request Dec 2, 2026
A cutout's maps (renderer/src/cutout.rs) are made of its triangles' texture
coordinates when the scene is prepared, and an instance an edit places takes
those of the scene's instances of its mesh. It took them too when the edit
had rewritten that mesh where it lies (a `dynamicGeometry` mesh, the same
sections): an emitter's shadow rays then asked the map of the triangles the
mesh had had. A card's texture coordinates mirrored at run time kept its old
picture of light and shadow on the ground.

The edit state keeps the meshes whose triangles an edit wrote (a new mesh, a
freed one's slot, one rewritten where it lies), and an instance of one takes
no map: its cutout is opaque to those rays, as a cutout whose material or
texture was edited already is, until the scene is prepared again. To make
the map again at the edit needs the texture's pixels and room in the maps'
stream then: not done.

`shadow/cutout-emitter-geometry-edit-live`: the card of
`shadow/cutout-emitter-side` with its u mirrored after three frames. The
point the old map lit, against a point a lamp under the card lights: 0.25
before (under both traversals), 0.003 now; with the alpha tested 0.085.

Unit suite 297, render suite 277 (on main with #305).

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant